package com.example.controller.usercoupon;

import com.example.enums.Status;
import com.example.pojo.BeforeuserAndCoupon;
import com.example.pojo.Usercoupon;
import com.example.pojo.Usercouponused;
import com.example.service.usercoupon.UserCouponService;
import com.example.service.usercoupon.UserCouponUsedService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@Slf4j
@Controller
@RequestMapping("/Coupon")
public class UserCouponController {
    @Autowired
    private UserCouponService userCouponService;
    @Autowired
    private UserCouponUsedService userCouponUsedService;



    /**
     * 功能描述: <获取优惠卷表格数据>
     * 〈〉
     * @Param: []
     * @Return: java.util.List<com.example.pojo.Usercoupon>
     * @Author: song
     * @Date: 2022/11/22 11:46
     */
    @ResponseBody
    @RequestMapping("/getTableData")
    public List<Usercoupon>  getTableData(Usercoupon usercoupon){
        log.info("获取了一次优惠卷表格");
        List<Usercoupon> all = userCouponService.getAll(usercoupon);
        return all;
    }
    /**
     * 功能描述: <修改优惠卷的上线下线状态>
     * 〈〉
     * @Param: [id, code]
     * @Return: int
     * @Author: song
     * @Date: 2022/11/22 11:56
     */
    @ResponseBody
    @RequestMapping("/UpdateOnline")
    public int UpdateOnline(Integer id,Integer code){
        Status status = userCouponService.UpdateOnline(id, code);
        log.info("修改了一次id为 {} 的优惠卷的状态",id);
        return status.getCODE();
    }
    /**
     * 功能描述: <添加优惠券>
     * 〈〉
     * @Param: [usercoupon]
     * @Return: boolean
     * @Author: song
     * @Date: 2022/11/22 20:31
     */
    @ResponseBody
    @RequestMapping("/addCoupon")
    public boolean addCoupon(@RequestBody Usercoupon usercoupon){
        log.info("添加了一个优惠卷");
        boolean b = userCouponService.addCoupon(usercoupon);
        return b;
    }
    /**
     * 功能描述: <删除指定优惠卷>
     * 〈〉
     * @Param: [id]
     * @Return: boolean
     * @Author: song
     * @Date: 2022/11/23 8:11
     */
    @ResponseBody
    @RequestMapping("/deleteCoupon")
    public boolean deleteCoupon(Integer id){
        boolean b = userCouponService.deleteCoupon(id);
        return b;
    }
    /**
     * 功能描述: <获取每个用户的优惠券信息>
     * 〈〉
     * @Param: []
     * @Return: java.util.List<com.example.pojo.BeforeuserAndCoupon>
     * @Author: song
     * @Date: 2022/11/23 18:30
     */
    @ResponseBody
    @RequestMapping("/getUserConpon")
    public List<BeforeuserAndCoupon> getUserConpon(String account,String nikename){
        List<BeforeuserAndCoupon> userCoupon = userCouponService.getUserCoupon(account,nikename);
        return  userCoupon;
    }
    /**
     * 功能描述: <查看某个用户的优惠券>
     * 〈〉
     * @Param: [uid]
     * @Return: java.util.List<com.example.pojo.Usercouponused>
     * @Author: song
     * @Date: 2022/11/24 15:59
     */
    @ResponseBody
    @RequestMapping("/getUserConponUsed")
    public List<Usercouponused> getUserConponUsed(int uid){
        List<Usercouponused> userCouponUseByUserId = userCouponUsedService.getUserCouponUseByUserId(uid);
        return userCouponUseByUserId;
    }
    /**
     * 功能描述: <br>
     * 〈赠送优惠卷〉
     * @Param: [uid, coupons]
     * @Return: boolean
     * @Author: song
     * @Date: 2023/2/1 14:03
     */
    @ResponseBody
    @RequestMapping("/giveCoupon")
    public boolean giveCoupon(int uid, int[] coupons){

        boolean b = userCouponUsedService.giveCoupons(uid, coupons);
        return b;
    }
}
